// 请求响应参数（不包含data）
import { ServiceResult } from "@/core/fetch/handle";
import { TPager } from "@/typings/global";

export interface Result {
  code: string;
  msg: string;
}

// 请求响应参数（包含data）
export interface ResultData<T = any> extends Result {
  data: T;
}

// 分页响应参数
export interface ResPage<T> {
  records: T[];
  pager?: TPager;
}

// 分页请求参数
export interface ReqPage {
  current?: number;
  size?: number;
}

// 文件上传模块
export namespace Upload {
  export interface ResFileUrl {
    fileUrl: string;
  }
}

// 登录模块
export namespace Login {
  export interface ReqLoginForm {
    username: string;
    password: string;
  }

  export interface ResLogin {
    code: number;
    data: {
      accessToken: string;
      refreshToken: string;
      userInfo: any;
    };
    msg: string;

    [prototype: string]: any;
  }

  export interface ResAuthButtons {
    [key: string]: string[];
  }
}

export namespace Role {
  export interface IRole {
    id?: number;
    roleName?: string;
    name?: string;
    roleCode?: string;
    description?: string;
    sortOrder?: number;
    isEnable?: number;
    createTime?: string;
    menus?: number[];
    deptIds?: number[];
  }

  export interface IRoleParams extends ReqPage {
    roleName?: string;
    roleCode?: string;
    isEnable?: number | string;
    createTime?: any[];
    startTime?: string;
    endTime?: string;
  }

  export interface IRoleUsers {
    roleId: number;
    users: number[];
  }

  export type TRoleListResult = ServiceResult<ResPage<IRole>>;
  export type TRoleDetailResult = ServiceResult<IRole>;
}

export namespace Dept {
  export interface IDept {
    id?: number;
    address?: string;
    deptCode: string;
    deptName: string;
    deptType: string;
    email?: string;
    fullName: string;
    leader?: string;
    orderNum: number;
    parentId: number | undefined;
    phone?: string;
    postalCode?: string;
    remark?: string;

    [property: string]: any;
  }

  export interface IDeptParams {
    name?: string;
    code?: string;
    pid?: number | undefined;
    status?: number | string;
  }

  export type TDeptListResult = ServiceResult<IDept[]>;
  export type TDeptPageListResult = ServiceResult<ResPage<IDept>>;
}

/**
 * @description 部门管理
 */
export namespace Post {
  export interface IPost {
    id?: number | string;
    name?: string;
    code?: string;
    status?: number | string | boolean;
    description?: string;
    sortOrder?: number;

    [prototype: string]: any;
  }

  export interface IPostParams extends ReqPage {
    name?: string;
    code?: string;
    status?: number | string;
  }

  export type TPostListResult = ServiceResult<ResPage<IPost>>;
  export type TPostDetailResult = ServiceResult<IPost>;
}

/**
 * @description 用户管理
 */
export namespace User {
  export interface IUser {
    id?: number;
    username?: string;
    deptId?: string;
    post?: number[];
    nickname?: string;
    email?: string;
    phone?: string;
    sex?: string;
    jobNumber?: string;
    name?: string;
    enName?: string;
    remark?: string;
    roles?: number[];
    status?: string;
  }

  export interface IUserParams extends ReqPage {
    username?: string;
    deptId?: string;
    post?: string;
    nickname?: string;
    email?: string;
    phone?: string;
    name?: string;

    [prototype: string]: any;
  }

  export type TUserListResult = ServiceResult<ResPage<IUser>>;
}

/**
 * @description 日志管理
 */
export namespace User {
  export interface ILogger {
    id?: number;
    logType?: string;
    logContent?: string;
    requestParam?: string;
    requestUrl?: string;
    requestMethod?: string;
    requestIp?: string;
    requestIpAddr?: string;
    requestTimeConsume?: string;
    browser?: string;
    os?: string;
    module?: string;
    responseHeader?: string;
    responseBody?: string;
    requestHeader?: string;
    requestBody?: string;
    status?: number;
  }

  export interface ILoggerParams extends ReqPage {
    createBy?: string;
    ip?: string;
    endTime?: string;
    startTime?: string;
    time?: [string, string];

    [prototype: string]: any;
  }

  export type TLoggerListResult = ServiceResult<ResPage<ILogger>>;
  export type TLoggerDetailResult = ServiceResult<ILogger>;
}
